import { ref } from "vue";
import { formatNumber } from "@/utils/util";
export const animationNumber = () => {
  const showNumber = ref(0);

  const setNumber = (newNum) => {
    let number = 0;
    const timer = setInterval(() => {
      showNumber.value = formatNumber(number);
      if (number < newNum) {
        number += 1000;
      } else {
        showNumber.value = formatNumber(newNum);
        clearInterval(timer);
      }
    }, 10);
  };

  return {
    showNumber,
    setNumber,
  };
};
